﻿using System;

namespace HomeWork5
{
    class Program
    {
        public abstract class graph
        {
            protected double height, hemline;
            public abstract double getArea();
        }

        public class triangle : graph
        {
            public triangle(double height, double hemline)
            {
                this.height = height;
                this.hemline = hemline;
            }
            public override double getArea()
            {
                return (height * hemline / 2);
            }
        }

        public class rectangle: graph
        {
            public rectangle(double height, double hemline)
            {
                this.height = height;
                this.hemline = hemline;
            }

            public override double getArea()
            {
                return (height * hemline);
            }
        }

        public class graphFactory
        {
            Random ran = new Random();
            public graph getGraph(int num)
            {
                int hei, hem;
                hei = ran.Next(1, 100);
                hem = ran.Next(1, 100);
                if(num == 1)
                    return new triangle(hei, hem);
                if (num == 0)
                    return new rectangle(hei, hem);
                else
                    return null;
            }
        }
        static void Main(string[] args)
        {
            graphFactory Factory = new graphFactory();
            Random random = new Random();
            double area = 0;
            int num = random.Next(1, 10000) % 2;
            for (int i = 1; i <= 10; i++)
            {
                graph Graph = Factory.getGraph(num);
                area += Graph.getArea();
            }
            Console.WriteLine("面积为:" + area.ToString());
        }
    }
}
